/**
 * 功能描述 列表
 */
define(function (require, exports, module) {
	var Grid = require("grid"); 	
	var aw = require("ajaxwrapper")
	
	var mailregister = require("../store/mailregister");
	
    var instance = {
        initComponent: function (params, widget) {
        	var indexgrid = new Grid({
                parentNode : ".J-grid",
                url : "api/mail/queryplan",
                autoRender:false,
                params : function(){
                	return {
        				year:widget.get("subnav").getValue("year"),
     					fetchProperties:mailregister.fetchProperties
                	};
                },
                model : {
                    columns : [{
                        name : "year",
                        label : "年度",
                        format:"date",
                        formatparams:{
							mode:"YYYY"
						}
                    },{
                        name : "verNumber",
                        label : "版本号",
                        format : "detail",
                        formatparams:{
                            handler:function(index,data,rowEle){
								widget.openView({
									url : "eling/elcms/travel/plan/src/plan_main",
									params: {
										"business" : "businessMain",
										pkPlan : data.pkPlan
									},
									isAllowBack:true
								})				
							}
                        }
                    },{
                        name : "planTitle",
                        label : "计划名称",
                    },{
                        name : "memberNum",
                        label : "会员数",
                    },{
                        name : "mailNum",
                        label : "已邮寄数",
//                        format:"detail",
//                        formatparams:{
//							key:"mail",
//                            handler:function(index,data,rowEle){
//								widget.hide([".J-grid"]).show([".J-grid-register"]);
//								widget.get("subnav").hide(["year"]).show(["search","product","return"]);
//								var plan = data.pkPlan;
//								widget.get("subnav").setValue("plan",plan);
//								widget.get("subnav").setValue("status",true);
//								widget.get("grid").refresh();
//							}
//                        }
                    },{
                        name : "publisher",
                        label : "发布人",
                    },{
                        name : "publisherDate",
                        label : "发布日期",
                        format : "date"
                    },{
                        name : "show",
                        label : "操作",
    					format:"button",
						formatparams:[{
							id:"register",
							text:"登记",
							handler:function(index,data,rowEle){
								 var plan = data.pkPlan;
								 widget.set("pkPlan", plan);
								 widget.get("subnav").setValue("plan",plan);
								 aw.ajax({
										url:"api/product/queryproductbymail",
										data:{
											fetchProperties:"pkProduct,name"
										},
										dataType:"json",
										success:function(data){
											widget.get("subnav").setData("product",data);
											 widget.hide([".J-grid"]).show([".J-grid-register"]);
											 widget.get("subnav").hide(["year"]).show(["search","product","status","operation","toexcel","return"]);
											 widget.get("subnav").setValue("status",false);
											 widget.get("grid").refresh();
										}
								 });
								 
							}
						}]
                    }]
                }
            });
        	widget.set("indexgrid",indexgrid);
        }
    };
    module.exports = instance;
});
